{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1、条件语句\n",
    "* Python条件语句是通过一条或多条语句的执行结果（True或者False）来决定执行的代码块\n",
    "* if...\n",
    "* if...else...\n",
    "* if...elif...elif...else...\n",
    "* 注意缩进问题"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x值大于50\n"
     ]
    }
   ],
   "source": [
    "# 简单if判断 → 单个条件\n",
    "x = 100\n",
    "if x > 50:\n",
    "    print('x值大于50')\n",
    "# 关于缩进 → 输入：之后回车自动缩进，如果要改变缩进用tab\n",
    "# 同一个缩进的代码组成一个代码块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x值大于50\n"
     ]
    }
   ],
   "source": [
    "# 简单if判断 → 两个条件\n",
    "x = 100\n",
    "if x > 50:\n",
    "    print('x值大于50')\n",
    "else:\n",
    "    print('x值小于等于50')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x值大于50\n"
     ]
    }
   ],
   "source": [
    "# 复杂if判断 → 多个条件\n",
    "x = 100\n",
    "if x > 50:\n",
    "    print('x值大于50')\n",
    "elif x == 50:\n",
    "    print('x值等于50')\n",
    "else:\n",
    "    print('x值小于50')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个整数：15\n",
      "反正这个值大于10\n"
     ]
    }
   ],
   "source": [
    "number = int(input('请输入一个整数：'))\n",
    "if number < 10:\n",
    "    print('该数字小于10')\n",
    "elif number == 12:\n",
    "    print('该数字居然恰恰等于12')\n",
    "elif number == 20:\n",
    "    print('该数字居然恰恰等于20')\n",
    "else:\n",
    "    print('反正这个值大于10')\n",
    "# 注意本身的逻辑"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2、循环语句\n",
    "* 这里介绍for循环 → for循环常用于遍历，比如list、str"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "这个学生的名字是小明\n",
      "这个学生的名字是小红\n",
      "这个学生的名字是小李子\n"
     ]
    }
   ],
   "source": [
    "# 分别查看学生名字\n",
    "students = ['小明','小红','小李子']\n",
    "for i in students:\n",
    "    print('这个学生的名字是%s' % i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world\n",
      "hello world\n",
      "hello world\n",
      "hello world\n",
      "hello world\n",
      "hello world\n",
      "hello world\n",
      "hello world\n",
      "hello world\n",
      "hello world\n"
     ]
    }
   ],
   "source": [
    "# 多次print\n",
    "for n in range(10):\n",
    "    print('hello world')\n",
    "# 这里输出‘hello world’10次\n",
    "# range()函数可创建一个整数列表，一般用在 for 循环中"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "该字母是不是h\n",
      "该字母是不是h\n",
      "该字母是不是h\n",
      "该字母是h\n",
      "该字母是不是h\n",
      "该字母是不是h\n"
     ]
    }
   ],
   "source": [
    "# for循环加判断语句\n",
    "for letter in 'Python':\n",
    "    if letter == 'h':\n",
    "        print( '该字母是h')\n",
    "    else:\n",
    "        print( '该字母是不是h')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 0\n",
      "0 1\n",
      "1 0\n",
      "1 1\n",
      "2 0\n",
      "2 1\n"
     ]
    }
   ],
   "source": [
    "# 嵌套循环\n",
    "for i in range(3):\n",
    "    for j in range(2):\n",
    "        print(i,j)"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
